﻿@using cloudscribe.Web.Navigation
@model NavigationViewModel
@if ((Model.TempNode != null) && (await Model.HasVisibleChildren(Model.TempNode)))
{
    @:<ul class="nav navbar-nav nav-second-level">

        @foreach (var childNode in Model.TempNode.Children)
        {
            if (! await Model.ShouldAllowView(childNode)) { continue; }

            if (! await Model.HasVisibleChildren(childNode))
            {
                if (childNode.EqualsNode(Model.CurrentNode))
                {
                    @:
                    <li class="active"><a class="active" href="@Url.Content(Model.AdjustUrl(childNode))">@childNode.Value.Text</a></li>
                }
                else
                {
                    @:
                    <li><a href="@Url.Content(Model.AdjustUrl(childNode))">@childNode.Value.Text</a></li>
                }
            }
            else
            {
                if (childNode.EqualsNode(Model.CurrentNode))
                {
                    <li class="active">
                        <a class="active" href="@Url.Content(Model.AdjustUrl(childNode))">
                            @childNode.Value.Text
                        </a>
                        @Model.UpdateTempNode(childNode)
                        @Html.Partial("SideNavPartial", Model) @* recursion *@
                    </li>
                }
                else
                {
                    <li>
                        <a href="@Url.Content(Model.AdjustUrl(childNode))">
                            @childNode.Value.Text
                        </a>
                        @Model.UpdateTempNode(childNode)
                        @Html.Partial("SideNavPartial", Model) @* recursion *@
                    </li>
                }
            }
        }
        @:</ul>
}
